Skip to content

Conversation

Bryanskiy
Copy link
Contributor

@Bryanskiy Bryanskiy commented Mar 26, 2024

fixes #119921
fixes #119919

There is no way to instantiate Self param for caller in delegation item if

  1. callee is a trait method && callee contains Self param
  2. delegation item isn't an associative item

In general, we can consider Self param as independent type param in these cases:

trait Trait {
    fn foo(_: Option<&Self>) {...}
}

reuse Trait::foo;
// will be desugared to:
fn foo<T: Trait>(x: Option<&T>) { Trait::foo(x) }

But this requires early bound parameters support. For now, I suggest banning such cases to avoid ICE's.

r? @petrochenkov

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 26, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 26, 2024

HIR ty lowering was modified

cc @fmease

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 26, 2024
@Bryanskiy Bryanskiy force-pushed the delegation-fixes-2 branch from 1d657a5 to eb3617b Compare March 27, 2024 12:17
@rust-log-analyzer

This comment has been minimized.

@Bryanskiy Bryanskiy force-pushed the delegation-fixes-2 branch from eb3617b to 0cd9708 Compare March 27, 2024 12:51
@Bryanskiy
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 27, 2024
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 27, 2024

📌 Commit 0cd9708 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 27, 2024
…trochenkov

Delegation: fix ICE on wrong `Self` instantiation

fixes rust-lang#119921
fixes rust-lang#119919

There is no way to instantiate `Self` param for caller in delegation item if

1. callee is a trait method && callee contains `Self` param
2. delegation item isn't an associative item

In general, we can consider `Self` param as independent type param in these cases:

```rust

trait Trait {
    fn foo(_: Option<&Self>) {...}
}

reuse Trait::foo;
// will be desugared to:
fn foo<T: Trait>(x: Option<&T>) { Trait::foo(x) }
```

But this requires early bound parameters support. For now, I suggest banning such cases to avoid ICE's.

r? `@petrochenkov`
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#121943 (Clarify atomic bit validity)
 - rust-lang#123089 (Add invariant to VecDeque::pop_* that len < cap if pop successful)
 - rust-lang#123101 (Delegation: fix ICE on wrong `Self` instantiation)
 - rust-lang#123130 (Load missing type of impl associated constant from trait definition)
 - rust-lang#123133 (chore: fix some comments)
 - rust-lang#123136 (Some wording improvement)
 - rust-lang#123139 (`num::NonZero::get` can be 1 transmute instead of 2)
 - rust-lang#123142 (Let nils know about changes to target docs)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#121943 (Clarify atomic bit validity)
 - rust-lang#123075 (CFI: Fix drop and drop_in_place)
 - rust-lang#123101 (Delegation: fix ICE on wrong `Self` instantiation)
 - rust-lang#123130 (Load missing type of impl associated constant from trait definition)
 - rust-lang#123133 (chore: fix some comments)
 - rust-lang#123136 (Some wording improvement)
 - rust-lang#123139 (`num::NonZero::get` can be 1 transmute instead of 2)
 - rust-lang#123142 (Let nils know about changes to target docs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ae33b90 into rust-lang:master Mar 28, 2024
@rustbot rustbot added this to the 1.79.0 milestone Mar 28, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 28, 2024
Rollup merge of rust-lang#123101 - Bryanskiy:delegation-fixes-2, r=petrochenkov

Delegation: fix ICE on wrong `Self` instantiation

fixes rust-lang#119921
fixes rust-lang#119919

There is no way to instantiate `Self` param for caller in delegation item if

1. callee is a trait method && callee contains `Self` param
2. delegation item isn't an associative item

In general, we can consider `Self` param as independent type param in these cases:

```rust

trait Trait {
    fn foo(_: Option<&Self>) {...}
}

reuse Trait::foo;
// will be desugared to:
fn foo<T: Trait>(x: Option<&T>) { Trait::foo(x) }
```

But this requires early bound parameters support. For now, I suggest banning such cases to avoid ICE's.

r? ``@petrochenkov``
@petrochenkov petrochenkov added the F-fn_delegation `#![feature(fn_delegation)]` label Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-fn_delegation `#![feature(fn_delegation)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE. delegation: index out of bounds with syntax error ICE: delegation: out of range when substituting
6 participants